<?php
/**
 * Created by Command.
 * User: Vito
 */

declare (strict_types = 1);

namespace app\admin\controller\v1;

use app\admin\controller\BaseController;
use app\logic\RoomLeaseRecordLogic;
use app\model\PayRecord;

class RoomLeaseRecord extends BaseController
{
    protected $name = '租房';

    protected $registerCurd = true;

    protected $registerCurdDir = true;
    protected $methodName = [
        'allot'             => '分配房间',
        'removeUser'        => '移除租户',
        'getPaidNumber'     => '获取用户待缴费数量',
        'saveMessage'       => '修改申请入住是否已通知'
    ];
    /**
     * 初始化
     */
    protected function initialize()
    {
        $this->logic = new RoomLeaseRecordLogic();
    }
    /**
     * @Description: 驳回申请
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-10-26 11:14:48
     * @version: 1.0.0
     * @return [type]
     */
    public function backRecord()
    {

        $params = $this->request->post();

        $res = $this->logic->backRecord($params);

        if ($res) {
            return success($res, '驳回成功');
        } else {
            return error('驳回失败');
        }
    }
    /**
     * @Description: 分配房间
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-10-26 11:14:48
     * @version: 1.0.0
     * @return [type]
     */
    public function allot(){

        $params = $this->request->post();

        $res = $this->logic->allot($params);
        
        if($res){
            return success($res,'分配成功');
        }else{
            return error('分配失败');
        }
    }
    /**
     * @Description: 移除用户
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-11-23 14:51:42
     * @version: 1.0.0
     * @return [type]
     */    
    public function removeUser(){

        $params = $this->request->post();


        $res = $this->logic->removeUser($params);

        if ($res) {
            return success($res, '移除成功');
        } else {
            return error('移除失败');
        }
            
    }

    /**
     * @Description: 获取待缴费数量
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2022-12-09 14:58:04
     * @version: 1.0.0
     * @return [type]
     */    
    public function getPaidNumber(){
        $params = $this->request->get();
        $PayRecordWhere['user_id'] = $params['user_id'];
        $PayRecordWhere['status']  = 0; //待支付字段
        $payRecord = PayRecord::withoutGlobalScope(['pid'])->where($PayRecordWhere)->count();

        return success($payRecord,'获取成功');

    }

    /**
     * @Description: 
     * @author: xiayu <cb1071403016@126.com>
     * @Date: 2023-10-31 09:52:45
     * @version: 1.0.0
     * @return 
     */    
    public function saveMessage(){
        $where['status']    = 0;
        $where['message']   = 0;
        $res =  $this->logic->getModel()->where($where)->update(['message'=>1]);
        return success($res,'修改成功');
    }
}
